package com.topvision.controller;

import com.topvision.entity.User;
import com.topvision.feign.UserFeignClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shengwm
 *
 */
@RestController
@Api(value = "DEMO", description = "DEMO")
public class FeignController {
  @Autowired
  private UserFeignClient userFeignClient;


  @GetMapping("feign/{id}")
  @PreAuthorize("hasAuthority('DEMO')")
  public User findByIdFeign(@PathVariable Long id) {
    System.out.println("=========================="+id+"=========================");
    User user = this.userFeignClient.findByIdFeign(id);
    return user;
  }


  @GetMapping("/demo")
  @ApiOperation(value="DEMO", notes="API DEMO")
  @PreAuthorize("hasAuthority('DEMO')")
  public String getDemo(){
   //String token =  clientContext.getAccessTokenRequest().getExistingToken().toString();
    return "good";
  }
}